package com.jhgsys.internal.sypq.service.impl;

import com.jhgsys.internal.sypq.entity.TaskTestbl1;
import com.jhgsys.internal.sypq.mapper.TaskTestbl1Mapper;
import com.jhgsys.internal.sypq.service.ITaskTestbl1Service;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.system.entity.User;
import org.apache.shiro.SecurityUtils;
import com.jhgsys.internal.common.entity.FebsConstant;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringPool;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 伴流试验 Service实现
 *
 * @author ganjun
 * @date 2024-12-11 00:59:51
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class TaskTestbl1ServiceImpl extends ServiceImpl<TaskTestbl1Mapper, TaskTestbl1> implements ITaskTestbl1Service {

    /**
     * 查询（分页）
     * @author ganjun
     * @date 2024-12-11 00:59:51
     * @param request QueryRequest
     * @param taskTestbl1 taskTestbl1
     * @return IPage<TaskTestbl1>
    */
    @Override
    public IPage<TaskTestbl1> findTaskTestbl1Page(QueryRequest request, TaskTestbl1 taskTestbl1) {
        LambdaQueryWrapper<TaskTestbl1> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TaskTestbl1::getDeletedFlg, 0);
        // TODO 设置查询条件

        Page<TaskTestbl1> page = new Page<>(request.getPageNum(), request.getPageSize());
        FebsUtil.pageWrapper(page, request);
        return this.page(page, queryWrapper);
    }

    /**
     * 查询（所有）
     * @author ganjun
     * @date 2024-12-11 00:59:51
     * @param taskTestbl1 taskTestbl1
     * @return List<TaskTestbl1>
     */
    @Override
    public List<TaskTestbl1> findTaskTestbl1List(TaskTestbl1 taskTestbl1) {
	    LambdaQueryWrapper<TaskTestbl1> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TaskTestbl1::getDeletedFlg, 0);
        queryWrapper.eq(TaskTestbl1::getTaskcode,taskTestbl1.getTaskcode());
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    /**
    * 根据ID查询
    * @author ganjun
    * @date 2024-12-11 00:59:51
    * @param id
    * @return TaskTestbl1
    */
    @Override
    public TaskTestbl1 findTaskTestbl1ById(String id){
        return this.baseMapper.selectById(id);
    }

    /**
     * 新增
     * @author ganjun
     * @date 2024-12-11 00:59:51
     * @param taskTestbl1 taskTestbl1
     */
    @Override
    @Transactional
    public boolean createTaskTestbl1(TaskTestbl1 taskTestbl1) {
        return this.save(taskTestbl1);
    }

    /**
     * 修改
     * @author ganjun
     * @date 2024-12-11 00:59:51
     * @param taskTestbl1 taskTestbl1
     */
    @Override
    @Transactional
    public boolean updateTaskTestbl1(TaskTestbl1 taskTestbl1) {
        return this.updateById(taskTestbl1);
    }

    /**
     * 逻辑删除
     * @author ganjun
     * @date 2024-12-11 00:59:51
     * @param taskTestbl1 taskTestbl1
     * @param taskTestbl1Ids taskTestbl1Ids
     */
    @Override
    @Transactional
    public boolean deleteTaskTestbl1(TaskTestbl1 taskTestbl1,String taskTestbl1Ids) {
        boolean result = false;
        User user = (User) SecurityUtils.getSubject().getPrincipal();
        List<String> list = Arrays.asList(taskTestbl1Ids.split(StringPool.COMMA));

        taskTestbl1.setDeletedBy(user.getUserName());
        taskTestbl1.setDeletedTime(new Date());
        taskTestbl1.setDeletedFlg(FebsConstant.INVALID);
        int update = this.baseMapper.update(taskTestbl1,new LambdaQueryWrapper<TaskTestbl1>().in(TaskTestbl1::getId,list));
        if (update > 0 ){
            result = true;
        }
        return result;
	}

    /**
    * 物理删除
    * @author ganjun
    * @date 2024-12-11 00:59:51
    * @param taskTestbl1Ids taskTestbl1Ids
    */
    @Override
    @Transactional
    public boolean physicallyDeleteTaskTestbl1(String taskTestbl1Ids) {
        List<String> list = Arrays.asList(taskTestbl1Ids.split(StringPool.COMMA));
        LambdaQueryWrapper<TaskTestbl1> wapper = new LambdaQueryWrapper<>();
        wapper.in(TaskTestbl1::getId,list);
        return this.remove(wapper);
    }
}
